package com.xinshujia.controller;

import com.xinshujia.config.mqtt.MqttGateway;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-25 17:41       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 */
@RestController
@RequestMapping("mqtt")
public class MqttController {
    private final MqttGateway mqttGateway;

    public MqttController(MqttGateway mqttGateway) {
        this.mqttGateway = mqttGateway;
    }

    @RequestMapping("send")
    public ResponseEntity<String> send(@RequestParam("topic") String topic, @RequestParam("payload") String payload) {
        mqttGateway.sendToMqtt(topic, payload);
        return new ResponseEntity<>("发送成功", HttpStatus.OK);
    }
}
